package icom.acm.admin.servlet;

import icom.acm.admin.been.AFunction;
import icom.acm.admin.manager.AFunctionMgr;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class for Servlet: AddFunction
 *
 */
 public class FunctionMgr extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public FunctionMgr() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*HttpSession session = request.getSession();
		User user = (User)session.getAttribute("user");
		if (user==null) return ;*/
		System.out.println("post");
		try {
			Integer f_id = Integer.parseInt(request.getParameter("f_id"));
			Integer f_pid = Integer.parseInt(request.getParameter("f_pid"));
			String f_name = new String(request.getParameter("f_name").getBytes("ISO-8859-1"),"GBK");
			String f_frame = request.getParameter("f_frame");
			String f_url = request.getParameter("f_url");
			if (f_name==null || f_name.equals("")) return ;
			else if (f_frame==null || f_frame.equals("")) return ;
			else if (f_url==null || f_url.equals("")) return ;
			
			AFunctionMgr funcm = new  AFunctionMgr();
			AFunction func = new AFunction();
			func.setF_ID(f_id);
			func.setF_PID(f_pid);
			func.setF_NAME(f_name);
			func.setF_FRAME(f_frame);
			func.setF_URL(f_url);
			if (f_id>0) // 更新
				funcm.update(func);
			else
				funcm.save(func);		// 保存节点
			response.sendRedirect("manager/functionmgr.jsp");
		} catch (Exception ex){
			System.out.println("error");
			ex.printStackTrace();
		}
	}   	  	    
}